package cn.signalpha.modules.shop.controller.admin;

import cn.signalpha.common.constant.AppConstant;
import cn.signalpha.core.boot.ctrl.BaseController;
import cn.signalpha.core.mp.support.Condition;
import cn.signalpha.core.mp.support.Query;
import cn.signalpha.core.tool.api.R;
import cn.signalpha.core.tool.utils.Func;
import cn.signalpha.modules.shop.dto.SellerApplyDTO;
import cn.signalpha.modules.shop.entity.SellerApply;
import cn.signalpha.modules.shop.service.SellerApplyService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.*;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.Map;

/**
 * 控制器
 *
 * @author signalpha
 */
@RestController
@AllArgsConstructor
@RequestMapping(AppConstant.APPLICATION_SHOP_NAME + "/admin/seller/apply")
@Api(value = "商户申请", tags = "商户申请")
public class SellerApplyController extends BaseController {

	private final SellerApplyService sellerApplyService;

    @GetMapping("/page")
	@ApiImplicitParams({
		@ApiImplicitParam(name="name", dataType = "string", value = "名称"),
		@ApiImplicitParam(name="mobile", dataType = "string", value = "电话"),
		@ApiImplicitParam(name="status", dataType = "string", value = "状态"),
		@ApiImplicitParam(name="typeId", dataType = "string", value = "类型id"),
		@ApiImplicitParam(name="categoryId", dataType = "string", value = "分类id"),
		@ApiImplicitParam(name="createTimeBegin", dataType = "string", value = "开始时间"),
		@ApiImplicitParam(name="createTimeEnd", dataType = "string", value = "结束时间"),
	})
    @ApiOperation(value = "分页", notes = "")
    public R<IPage<SellerApply>> page(@ApiIgnore @RequestParam Map<String, Object> params, Query query) {
		QueryWrapper<SellerApply> wrapper = sellerApplyService.selectSellerApplyWrapper(params);
		return R.data(sellerApplyService.page(Condition.getPage(query), wrapper));
    }

	@GetMapping("/info")
	@ApiOperation(value = "详情", notes = "传入id")
	public R<SellerApply> info(@ApiParam(value = "主键", required = true) @RequestParam Long id) {
		return R.data(sellerApplyService.getById(id));
	}

	@PostMapping("/audit")
	@ApiOperation(value = "审核", notes = "")
	public R audit(@Valid @RequestBody SellerApplyDTO.AuditDTO auditDTO) {
		Func.toLongList(auditDTO.getIds()).forEach(id -> {
			sellerApplyService.sellerApplyAudit(id, auditDTO);
		});
		return R.status(true);
	}

	@PostMapping("/remove")
	@ApiOperation(value = "删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(sellerApplyService.removeByIds(Func.toLongList(ids)));
	}

}
